<template>
<div style="height:700px;padding:20px 50px;overflow-y: auto; ">
  <el-button class="filter-item" size="mini" type="success" icon="el-icon-back"   @click="back">返回</el-button>
  <div class="head_title">基本信息</div>
  <el-form ref="form" :model="form" :rules="rules" style="margin-top: 16px;" size="small" label-width="160px">
	<el-form-item label="客户名称"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.custName" style="width: 370px;"/>
    </el-form-item>
	 <el-form-item label="填报日期" style="display:inline-block;width:48%;margin-bottom:-3px">
						<el-form-item prop="date1">
								<el-date-picker  type="date"   v-model="form.fillInDate" style="width: 370px;"></el-date-picker>
						</el-form-item>			
	 </el-form-item>
	<el-form-item label="填报类型"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.fillInType" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="是否审计"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.isAudit" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="会计准则"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.accountStandard" style="width: 370px;"/>
    </el-form-item>
     <el-form-item label="审计日期" style="display:inline-block;width:48%;margin-bottom:-3px">
						<el-form-item prop="date1">
								<el-date-picker  type="date"   v-model="form.auditDate" style="width: 370px;"></el-date-picker>
						</el-form-item>			
	 </el-form-item>
	 <el-form-item label="是否经我行认可"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.isMyBankApprovel" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="登记机构"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.registDept" style="width: 370px;"/>
    </el-form-item>
    <el-form-item label="登记日期" style="display:inline-block;width:48%;margin-bottom:-3px">
						<el-form-item prop="date1">
								<el-date-picker  type="date"   v-model="form.registDate" style="width: 370px;"></el-date-picker>
						</el-form-item>			
	 </el-form-item>
     <el-form-item label="更新日期" style="display:inline-block;width:48%;margin-bottom:-3px">
						<el-form-item prop="date1">
								<el-date-picker  type="date"   v-model="form.updateDate" style="width: 370px;"></el-date-picker>
						</el-form-item>			
	 </el-form-item>
	<el-form-item label="导入日期" style="display:inline-block;width:48%;margin-bottom:-3px">
						<el-form-item prop="date1">
								<el-date-picker  type="date"   v-model="form.importDate" style="width: 370px;"></el-date-picker>
						</el-form-item>			
	 </el-form-item>
	<el-form-item label="审计事务所名称"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.auditFirmName" style="width: 370px;"/>
    </el-form-item>
  </el-form>
  <div class="head_title space">客户损益信息</div>
  <div  style="display:flex;justify-content:center">
	  <div v-html='profitlossHtml'></div>
  </div>				
  </div>
</template>

<script>
import { get, update } from '@/api/alipay'
import { general,list,credentials,addCredentials,effective,debt,assets} from '@/api/custComBaseinfo'
import initData from '@/mixins/initData'
import { parseTime } from '@/utils/index'
import checkPermission from '@/utils/permission'
export default {
  name: 'Config',
  mixins: [initData],
  data() {
    return {
	  dialog:false,
	  loading: false,
	  addLoading:false,
	  id:'',
      form: { 
		   custName:'',
		   fillInDate:'',
		   fillInType:'',
		   isAudit:'',
		   accountStandard:'',
		   auditDate:'',
		   isMyBankApprovel:'',
		   registDept:'',
		   registDate:'',
		   updateDate:'',
		   importDate:'',
		   auditFirmName:''
		
		 },
		  reqForm:{
			page: 0, 
			size: 10,
			sort:'id,desc',
			id:''
		},
		reqData:{
			recordId:''
		},
        reqAssetsData:{
			financeInfoType:'t_cust_com_finance_fund',
			recordId:''
		},
		reqLoanData:{
			financeInfoType:'t_cust_com_finance_loan',
			recordId:''
		},
		reqCashData:{
			financeInfoType:'t_cust_com_finance_cashflow',
			recordId:''
		},
		reqProfitlossData:{
			financeInfoType:'t_cust_com_finance_profitloss',
			recordId:''
		},
		assetsHtml:'',
		loanHtml:'',
		cashFlowHtml:'',
		profitlossHtml:'',
		reqLoading:true,
		reqId:'',
		reqIds:[],
	    addForm:{
		   cardCountry:'',
		   cardType:'',
		   cardNum:'',
		   cardEndDate:'',
		   cardStatus:'',
		   cardPublishCity:'',
		   isMainCard:''
		},
		addRules: {
				cardCountry: [
				  { required: true, message: '请输入证件国别', trigger: 'blur' }
				],
				cardType: [
				  { required: true, message: '请输入证件类型', trigger: 'blur' }
				],
				cardNum: [
				  { required: true, message: '请输入证件编号', trigger: 'blur' }
				],
				cardEndDate: [
				  { required: true, message: '请输入证件到期日期', trigger: 'blur' }
				],
				cardStatus: [
				  { required: true, message: '请输入证件状态', trigger: 'blur' }
				],
				cardPublishCity: [
				  { required: true, message: '请输入证件发布城市', trigger: 'blur' }
				],
		        isMainCard: [
				  { required: true, message: '请输入是否主证件', trigger: 'blur' }
				]

		},

		effectiveParams:{
		   id:'',
		   cardStatus:''
		},
      rules: {
        appID: [
          { required: true, message: '请输入appID', trigger: 'blur' }
        ],
        sysServiceProviderId: [
          { required: true, message: '请输入商家账号', trigger: 'blur' }
        ],
        privateKey: [
          { required: true, message: '商户私钥不能为空', trigger: 'blur' }
        ],
        publicKey: [
          { required: true, message: '支付宝公钥不能为空', trigger: 'blur' }
        ],
        returnUrl: [
          { required: true, message: '回调地址不能为空', trigger: 'blur' }
        ],
        notifyUrl: [
          { required: true, message: '回调地址不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
	  	setTimeout(() => {
				this.reqData.recordId = sessionStorage.getItem('comFinanceId')
				this.reqProfitlossData.recordId  = sessionStorage.getItem('comFinanceId')
				 this.loading = true
				 let that = this
			    debt(this.reqData).then(res => {
					this.form = {
						    custName:res.custName,
							fillInDate:res.fillInDate,
							fillInType:res.fillInType,
							isAudit:res.isAudit,
							accountStandard:res.accountStandard,
							auditDate:res.auditDate,
							isMyBankApprovel:res.isMyBankApprovel,
							registDept:res.registDept,
							registDate:res.registDate,
							updateDate:res.updateDate,
							importDate:res.importDate,
							auditFirmName:res.auditFirmName
					}
					setTimeout(() => {
						this.reqLoading = false
					}, 170)
				}).catch(err => {
					this.reqLoading = false
					console.log(err.response.data.message)
				})
	
				assets(this.reqProfitlossData).then(res => {
					this.profitlossHtml = res
					console.log('this.profitlossHtml',this.profitlossHtml)
					setTimeout(() => {
						this.reqLoading = false
					}, 170)
				}).catch(err => {
					this.reqLoading = false
					console.log(err.response.data.message)
				})





         }, 500)
	  
  },
  methods: {
	   parseTime,
	   checkPermission,
    init() {
	  
        // this.delLoading = true
      general(this.id).then(res => {
        // this.delLoading = false
        // this.$refs[id].doClose()
        // this.dleChangePage()
        // this.init()
        // this.$notify({
        //   title: '删除成功',
        //   type: 'success',
        //   duration: 2500
        // })
      }).catch(err => {
        // this.delLoading = false
        // this.$refs[id].doClose()
        // console.log(err.response.data.message)
      })



    //   get().then(res => {
    //     this.form = res
    //   })
	},
	handleSelectionChange(val) {
		  console.log('val',val)
		   val.forEach((v) => {
               this.reqIds.push(v.id)
		   });
		   console.log('ids',this.reqIds)
		   this.reqId = this.reqIds.toString()
		   this.reqIds = []
	},
	back(){
		 this.$router.go(-1)
	},
	add(){
		this.dialog = true;
	},
	cancelAdd(){
		this.resetForm()
	},
	resetForm() {
      this.dialog = false
	  this.$refs['forms'].resetFields()
	  this.addForm ={
		   cardCountry:'',
		   cardType:'',
		   cardNum:'',
		   cardEndDate:'',
		   cardStatus:'',
		   cardPublishCity:'',
		   isMainCard:''
	  }
	},
	addCredentials(){
		  this.$refs['forms'].validate((valid) => {
				if (valid) {
				this.addLoading = true
				addCredentials(this.addForm).then(res => {
					this.$notify({
					title: '新增成功',
					type: 'success',
					duration: 2500
					})
					this.credentials();
					this.addLoading = false
					this.dialog = false;
				}).catch(err => {
					this.addLoading = false
					console.log(err.response.data.message)
				})
				} else {
				return false
				}
			})
	},
	credentials(){
              credentials(this.reqForm).then(res => {
					this.total = res.totalElements
					this.data = res.content
					setTimeout(() => {
						this.reqLoading = false
					}, 170)
				}).catch(err => {
					this.reqLoading = false
					console.log(err.response.data.message)
				})
	},
	 effective(){
		 this.effectiveParams.id = this.reqId
		 this.effectiveParams.cardStatus = '1' 
		 if(this.effectiveParams.id == ''){
			this.$message.warning('请选择某个复选框') 
			return;
		 }
        effective(this.effectiveParams).then(res => {
            this.$notify({
              title: '已生效',
              type: 'success',
              duration: 2500
			})
			this.credentials();
            // this.loading = false
          }).catch(err => {
            // this.loading = false
            console.log(err.response.data.message)
          })
	 }, 

	 invalid(){
		 this.effectiveParams.id = this.reqId
		 this.effectiveParams.cardStatus = '0' 
		 if(this.effectiveParams.id == ''){
			this.$message.warning('请选择某个复选框') 
			return;
		 }
        effective(this.effectiveParams).then(res => {
            this.$notify({
              title: '已失效',
              type: 'success',
              duration: 2500
			})
			this.credentials();
            // this.loading = false
          }).catch(err => {
            // this.loading = false
            console.log(err.response.data.message)
          })
	 }, 

    doSubmit() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.loading = true
          update(this.form).then(res => {
            this.$notify({
              title: '修改成功',
              type: 'success',
              duration: 2500
            })
            this.loading = false
          }).catch(err => {
            this.loading = false
            console.log(err.response.data.message)
          })
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style scoped> 
  .head_title{
    height:40px;line-height:40px;border-bottom: 2px solid #ce2731;color:#ce2731
  }
  .space{
	  margin-top:30px;
	  margin-bottom:10px
  }
   .one{
	   display:inline-block;
	   width:86.5%;
   }
   .two{
	   display:inline-block;
	   width:50%;
	
   }


</style>
